package com.ctsi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctsi.core.common.util.StringUtil;
import com.ctsi.core.database.entity.Search;
import com.ctsi.core.database.util.PageUtil;
import com.ctsi.system.entity.Client;
import com.ctsi.system.mapper.ClientMapper;
import com.ctsi.system.service.IClientService;
import org.springframework.stereotype.Service;

/**
 * @version 1.0
 * @author: wang xiao xiang
 * @date: 2022/7/5 14:23
 */
@Service
public class ClientServiceImpl extends ServiceImpl<ClientMapper, Client> implements IClientService {

    @Override
    public IPage<Client> listPage(Search search) {
        LambdaQueryWrapper<Client> queryWrapper = Wrappers.lambdaQuery();
        if (StringUtil.isNotBlank(search.getKeyword())) {
            queryWrapper.like(Client::getClientId, search.getKeyword())
                    .or().like(Client::getClientName, search.getKeyword());
        }
        queryWrapper.orderByDesc(Client::getCreateTime);
        return this.baseMapper.selectPage(PageUtil.getPage(search), queryWrapper);
    }
}